<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>华胜后台管理</title>
		<link rel="stylesheet" type="text/css" href="css/unified.css">
		<script src="plugins/layui/layui.js"></script>

		<style type="text/css">

		</style>
	</head>

	<body>

		<fieldset class="layui-elem-field layui-field-title">
			<legend>商品库存信息</legend>
			<div class="layui-field-box">
				<table class="layui-table smtable"  id="stockinTable">
					<thead>
						<tr>
							<td style="width: 28px;">操作</td>
							<td>状态</td>
							<td>条码</td>
							<td>商品编码</td>
							<td>名称</td>
							<td>产品图片</td>
							<td>商家编号</td>
							<td>库存地点</td>
							<td>库存数量</td>
							<td>出库数量</td>
						</tr>
					</thead>
					<tbody>
						<!--<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
		</tr>-->
					</tbody>
					<tfoot>
						<tr>
							<td colspan='100%' id="addtr">点击添加+</td>
						</tr>
					</tfoot>
				</table>
			</div>
		</fieldset>

		<fieldset class="layui-elem-field layui-field-title">
			<legend>出库</legend>
			<div class="layui-field-box">
				<form class="layui-form layui-form-pane IntTable" action="">

					<div class="layui-col-xs12 layui-col-sm6 layui-col-md3">
						<div class="layui-form-item">
						    <label class="layui-form-label">批次<span class="layui-badge-dot"></span></label>
						    <div class="layui-input-block">
						      <input type="text" name="batchId" autocomplete="off" placeholder="" class="layui-input inputRequired" value="">
						    </div>
						 </div>
					</div>
					<div class="layui-col-xs12 layui-col-sm6 layui-col-md3">
						<div class="layui-form-item">
						    <label class="layui-form-label">出货点编码<span class="layui-badge-dot"></span></label>
						    <div class="layui-input-block">
						      <input type="text" name="fromLocationId" autocomplete="off" placeholder="" class="layui-input inputRequired" value="">
						    </div>
						 </div>
					</div>
					
					
					<div class="layui-col-xs12 layui-col-sm6 layui-col-md3">
						<div class="layui-form-item">
						    <label class="layui-form-label">备注</label>
						    <div class="layui-input-block">
						      <input type="text" name="comment" autocomplete="off" placeholder="" class="layui-input">
						    </div>
						 </div>
					</div>
					
				</form>

			</div>
		</fieldset>
		<div class="layui-layer-btn layui-layer-btn-" style="margin-bottom: 35px;">
			<div class="layui-btn yesInsert">确认商品出库</div>
			<div class="layui-btn layui-btn-normal " id="print">打印</div>
			<!--<div class="layui-btn layui-bg-gray noInsert">取消</div>-->
		</div>
		
		<!--startprint-->
		<div class="goodsBox" id="print_content" ></div>
		<!--endprint-->
		
		<script id="ComManagement" type="text/html">
			<table class="layui-table " lay-filter="table100" id="cMtable"></table>
		</script>
	</body>

	<script src="js/jquery-3.2.1.min.js"></script>
	<script src="js/allajax.js"></script>
	<script>
		//	$(".stockinTable")
		layui.use(['layer', 'form', 'element', 'table', 'laydate', 'laypage'], function() {
			var layer = layui.layer,
				form = layui.form,
				element = layui.element,
				table = layui.table,
				laydate = layui.laydate,
				laypage = layui.laypage;
				AjaxPostFn('system/bizmerchantinfo/select?page=1&pagesize=10', '{}', function(data) {  	
					//获取商家
					if(data.pageInfo.size != 0) {
						$.each(data.pageInfo.list, function(idx,obj) {
							$("#merchantNumselect").append("<option value='"+obj.merchantNumber+"'>"+obj.merchantName+"</option>");  
						});
						form.render();
						
						
					}else{
						
					}
				})
			
			
				
			$("#addtr").click(function() {
				console.log("111")
				var index = layer.open({
					type: 2,
					title: "商品库存信息",
					area: ['100%', '100%'],
					maxmin: true,
					shade: 0,
					content: 'stock_now.html?urltype=choice'
				});

			})
			$(".yesInsert").click(function(){
				if($("#stockinTable tbody tr").length != 0 ){
					//选取了商品基础信息
					inputisNull('.inputRequired',function(){
						
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
						var injson = $(".IntTable").serializeJson();
						$.each($("#stockinTable tbody tr"), function(idx,obj) {
							var Trstats =  $("#stockinTable tbody tr:eq("+idx+") td:eq(1)").attr("data-stats");
							if(Trstats == 0){

								injson.barCode = $("#stockinTable tbody tr:eq("+idx+") .InBarCode").html();
								injson.createTime = new Date().getTime();
								injson.toLocationId =  $("#stockinTable tbody tr:eq("+idx+") .NowlocationId").html();
								injson.theNum = $("#stockinTable tbody tr:eq("+idx+") .NowtheNum").val();
								injson.NowmerchantNumber = $("#stockinTable tbody tr:eq("+idx+") .NowmerchantNumber").html();
								var thisidx  = idx;
								AjaxPostFn('system/repository/out/insert', JSON.stringify(injson), function(data ) {
								 	console.log(thisidx)
								 	var thistd = $("#stockinTable tbody tr:eq("+thisidx+") td:eq(1)")
								 
//									(function(thisidx){
										if(data.htmlState.status == 200) {
	//										layer.msg("入库成功");
	
											thistd.html("出库成功");
											thistd.css("color","#0db832");
											thistd.attr("data-stats","1");
										}else{
											
	//										layer.msg(data.htmlState.message);
											thistd.html("出库失败");
											thistd.css("color","#ff2d2d");
											thistd.attr("data-stats","2");
										}
										
										 console.log($("#stockinTable tbody tr:eq("+thisidx+") td:eq(1)").html())
//									})(thisidx)
									
									  
									
								} , thisidx);
								
//								AjaxPostFn('system/repository/prepare/insert', JSON.stringify(injson), function(data ) {
//									if(data.htmlState.status == 200) {
//										
//									}
//								})
	//							if(tf){
	//								setTimeout(function(){
	//									parent.layer.close(index)
	//								},1000);
	//							}
								}
							
							 
						});
						
						
//							parent.stockAddlist( 1 , 100 , '{}');
//						
					})
				}else{
					layer.msg("请选择至少一件商品")
				}
				
			
			})
			
			$("#print").click(function(){
				//打印当前入库单
				if($("#stockinTable tbody tr").length == 0){
					
					layer.msg("选择一样商品")
					
				}else{
					var print_click = "print"; //打印的按钮的id
				var printfStr='<div class="goods_titlebox"><img src="img/logo.jpg" class="goodslogo"/><div class="goods_title">深圳市华胜集团有限公司<br />宝安批发中心入库单</div></div>'+
					'<div class="goods_Basics">'+
						'<div class="layui-col-xs6 layui-col-sm6 layui-col-md6"><label>客户地址:</label>'+$("input[name='supplierName']").val()+'</div>'+
						'<div class="layui-col-xs6 layui-col-sm6 layui-col-md6"><label>单据编号:</label></div>'+
						'<div class="layui-col-xs6 layui-col-sm6 layui-col-md6"><label>送货地址:</label>'+ $("input[name='supplierContact']").val()+'	</div>'+
						'<div class="layui-col-xs6 layui-col-sm6 layui-col-md6"><label>日期:</label></div>'+
						'<div class="layui-col-xs6 layui-col-sm6 layui-col-md6"><label>客户电话:</label></div>'+
						'<div class="layui-col-xs6 layui-col-sm6 layui-col-md6"><label>指定收货人:</label></div>'+
					'</div>'+
					'<table class="goods_table" border="1" >'+
						'<thead><tr><td>商品编号</td><td>商品全名</td><td>单位</td><td>数量</td><td>单价</td><td>金额</td><td>备注</td></tr></thead>';
						
						var total = 0;
						$("#stockinTable tbody").find("tr").each(function(){
							
							var arrtd = $(this).children();
//							var psn = arrtd.eq(0).text();
//							
//							var scoreInput = arrtd.eq(1).find("input");
//							
//							var scoreNum = $("input[name='grade"+x+"']:checked").val();
//							var psn = arrtd.eq(1).find("span").text();
//							x++;
							var thisobj = $("#stockinTable tbody tr");
							var thistotolP = arrtd.eq(12).children().val() * arrtd.eq(13).children().val();
							printfStr+='<tbody><tr><td>'+arrtd.eq(2).text()+'</td><td>'+arrtd.eq(3).text()+'</td><td>'+
							arrtd.eq(9).text()+'</td><td>'+arrtd.eq(12).children().val()+'</td><td>'+arrtd.eq(13).children().val()+
							'</td><td>'+thistotolP+'</td><td>'+arrtd.eq(15).children().val()+'</td></tr></tbody>';
							total += thistotolP;
						})

						if(total == 0){
							layer.msg("价格为0");
							return false;
						}
						

						printfStr+='<tfoot><tr><td>总计</td><td colspan="4">'+Arabia_to_Chinese('￥'+total)+'</td><td>'+total+'</td><td></td></tr></tfoot>'+
					'</table>'+
					'<b class="goods_Remarks">备注：本送货单作为欠款凭证，如有异议，双方在深圳市保宝安区人民法院诉讼解决。如有质量问题，请在7天之内书面提出，否则视同默认。</b>'+
					'<p class="goods_type">1、存根（白） 2、发货（红） 3、客户（绿） 4、回单（蓝） 5、记账（黄）</p>'+
					'<div class="goods_foot"><div class="goods_foot5">制单:</div><div class="goods_foot5">复核:</div><div class="goods_foot5">发货:</div><div class="goods_foot6">客户签名(未付款):</div><div class="goods_foot5">担保人:</div></div>'+
					'<div class="goods_footem"><div class="">地址:深圳市宝安区宝安大道三围村宝安建材中心9栋1号华胜木业有限公司</div><div class="">电话:0755-27836166</div><div class="">传真:0755-27836233</div></div>';
					
					$("#print_content").show()
					$("#print_content").html(printfStr);
					
					$("#print_content").print({
			        	globalStyles: true,
			        	mediaPrint: false,
			        	stylesheet: null,
			        	noPrintSelector: ".no-print",
			        	iframe: true,
			        	append: null,
			        	prepend: null,
			        	manuallyCopyFormValues: true,
			        	deferred: $.Deferred(),
			        	timeout: 750,
			        	title: null,
			        	doctype: '<!doctype html>'
					});
					
					$("#print_content").hide()
				}
				
				
			})
			
		})
		
		
		function deltr (objidx){
		
//			layer.confirm('是否要删除当前选中行信息', function(index){
//			  //do something
			  $("#stockinTable tbody tr:eq("+objidx+")").remove();
//			  layer.close(index);
//			});    
			
		}
	</script>

</html>